#pragma once
#include "MainWindowBase.h"
#include "SquareFinder.h"
#include "OptionPanel_ShapeDetection.h"
#include "OptionPanel_EdgeDetection.h"
#include "OptionPanel_Pyr_LK.h"
#include "OptionPanel_FaceDetection.h"
#include <map>

namespace OCEANUI{
	class CDockPanelManager;
	class CCentralCanvasBase;
	class CMainWindow:	
		public CMainWindowBase
	{
		Q_OBJECT
	
		enum CentralWidgetType
		{
			PaintCanvas = 0,
			VideoCanvas,
			CamCanvas,
		};
	public:
		CMainWindow(void);

		~CMainWindow(void);

		void OnImageChanged(IplImage* pImage);

	public slots:
		void OnFileOpen();
		void OnCamOpen();
		void OnRectangleDetectionClicked();
		void OnSobelOperatorActClicked();
		void OnPrewittOperatorClicked();
		void OnLogOperatorClicked();
		void OnCannyDetectionClicked();

		void OnPyr_LKClicked();

		void OnStaticFaceDetectionActClicked();
		void OnVideoFaceDetectionActClicked();
		void draw(QAction* action);
	private:
		 void createDockWindows_();
		 CCentralCanvasBase* setCurrentCentralCanvas_(CentralWidgetType newType);
		 void createActions();
		 void createToolBars();
		 void createMenus();
	private:
		
		QPixmap pix;
		OCEANUI::CCentralCanvasBase* form;
		CCentralCanvasBase* CentralCanvasGroup[3]; 
        QImage image;
		IplImage* pCurrentImage_;

		QAction *lineAct;
		QAction *polylineAct;
		QAction *rectangleAct;
		QAction *polygonAct;
		QAction *arcAct;
		QAction *pieAct;
		QAction *chordAct;
		QAction *ellipseAct;
		QAction *textAct;

		QAction* openAct;
		QAction* openCamAct;
		
		QAction* rectangleDetectionAct;
		QAction* sobelOperatorAct;
		QAction* prewittOperatorAct;
		QAction* logOperatorAct;
		QAction* cannyDetectionAct;

		QAction* pyr_LKAct;

		QAction* staticFaceDetectionAct;
		QAction* videoFaceDetectionAct;

		QActionGroup *drawActGroup;
		QToolBar *drawToolBar;
		//QFontComboBox *fontCmb;
		QMenu *drawMenu;
		QMenu *fileMenu;
		QMenu *edgeDetectionMenu;
		QMenu *shapeDetectionMenu;
		QMenu *trackingDetectionMenu;
		QMenu *faceDetectionMenu;
		QDockWidget *dock;
		OCEANUI::CDockPanelManager* pPanelManager;
		QWidget* q;

	};

	class CDockPanelManager
	{

	public:
		CDockPanelManager(QDockWidget *dock,QMainWindow* dockParent):
				pDock_(dock),
				pDockParent(dockParent),
				pCurrentPanel(0)
		{
			assert(NULL != dock);
		}
		void ShowPanel(CPanelBase* pPanel)
		{
			
			//if (NULL != pCurrentPanel)
			//	pCurrentPanel->hide();
			pCurrentPanel = pPanel;
			pDock_ = pPanel->getDockWidget();
			pDock_->setMinimumSize(pCurrentPanel->size());
			pDockParent->addDockWidget(Qt::LeftDockWidgetArea, pDock_);
			pDock_->move(0,0);
			
		}

		CPanelBase* AddPanel(std::string strPanelName)
		{

			CPanelBase* pPanel = NULL;
			iterPanel = mapPanel_.find(strPanelName);
			if (iterPanel == mapPanel_.end())
			{
				if ( strPanelName == "OptionPanel_EdgeDetection")
				{
					pPanel = new CPanel_EdgeDetection(pDockParent);
					pPanel->init();
					mapPanel_[strPanelName] = pPanel;
					 
				}
				else if ( strPanelName == "OptionPanel_ShapeDetection")
				{
					pPanel = new CPanel_ShapeDetection(pDockParent);
					pPanel->init();
					mapPanel_[strPanelName] = pPanel;
					 
				}
				else if ( strPanelName == "OptionPanel_Pyr_LK")
				{
					pPanel = new CPanel_Pyr_LK(pDockParent);
					pPanel->init();
					mapPanel_[strPanelName] = pPanel;
				}
				else if ( strPanelName == "OptionPanel_FaceDetection")
				{
					pPanel = new CPanel_FaceDetection(pDockParent);
					pPanel->init();
					mapPanel_[strPanelName] = pPanel;
				}
				return pPanel;
			}
			return mapPanel_[strPanelName];
		}


	private:
		std::map<std::string,CPanelBase*> mapPanel_;
		std::map<std::string,CPanelBase*>::iterator iterPanel;
		CPanelBase* pCurrentPanel;
		QDockWidget * pDock_;
		QMainWindow * pDockParent;
		

	};
}
